package leetcode.code072;

public class Solution extends Solution072 {

	@Override
	public int minDistance(String word1, String word2) {
		char[] w1 = word1.toCharArray();
		char[] w2 = word2.toCharArray();
		int[][] dp = new int[w1.length + 1][w2.length + 1];
		for (int i = 1; i <= w1.length; i++) {
			dp[i][0] = i;
		}
		for (int i = 1; i <= w2.length; i++) {
			dp[0][i] = i;
		}
		for (int i = 1; i <= w1.length; i++) {
			for (int j = 1; j <= w2.length; j++) {
				if (w1[i - 1] == w2[j - 1]) {
					dp[i][j] = dp[i - 1][j - 1];
				} else {
					dp[i][j] = dp[i - 1][j - 1] + 1;
				}
				dp[i][j] = Math.min(dp[i][j], dp[i - 1][j] + 1);
				dp[i][j] = Math.min(dp[i][j], dp[i][j - 1] + 1);
			}
		}
		return dp[w1.length][w2.length];
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();

	}

}
